package com.work.formaldehyde.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.umeng.analytics.MobclickAgent;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activityadapter.CityCheckGirdAdapter;
import com.work.formaldehyde.activityadapter.CommentAdapter;
import com.work.formaldehyde.model.ShangPingXiangQingModel;
import com.work.formaldehyde.util.ApiUtils;

import java.util.ArrayList;

public class CommentActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private ImageView jiance_comeback;
    private ListView comment_check_list;
    private LinearLayout addview;
    private ImageView home_title_share;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ApiUtils.ActivityIsLogin(this, 1);
        setContentView(R.layout.activity_commentcity);
        jiance_comeback = findViewById(R.id.jiance_comeback);
        jiance_comeback.setOnClickListener(this);
        if (ApiUtils.isNetworkConnected(CommentActivity.this))
            inti();
    }

    public static ArrayList<String> new_list_views;
    private CommentAdapter myAdapters;
    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
    /**
     * 初始加载热门视图
     */
    public void Init() {
        new_list_views = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            new_list_views.add("1");
        }
        myAdapters = new CommentAdapter(new_list_views, ShangPingActivity.comment,
                CommentActivity.this);
        comment_check_list.setAdapter(myAdapters);
    }


    /**
     * 初始化加载调用方法
     */
    public void inti() {
        home_title_share = findViewById(R.id.home_title_share);
        home_title_share.setOnClickListener(this);
        addview = findViewById(R.id.addview);
        comment_check_list = findViewById(R.id.comment_check_list);
        comment_check_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                if (new_list_views.get(i).equals("0")) {
//                    new_list_views.set(i, "1");
//                } else {
//                    new_list_views.set(i, "0");
//                }
//                myAdapters.notifyDataSetChanged();
            }
        });
        Init();
        for (int s = 0; s < 3; s++) {
            RelativeLayout relativeLayout = new RelativeLayout(CommentActivity.this);
            TextView textView = new TextView(CommentActivity.this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(24, 24, 0, 24);
            LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp1.setMargins(24, 6, 24, 6);
            LinearLayout.LayoutParams lps = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            relativeLayout.setLayoutParams(lp);
            relativeLayout.setBackgroundResource(R.drawable.dazhe_text_rela);
            textView.setLayoutParams(lp1);
            textView.setText("满100减" + s);
            textView.setTextColor(getResources().getColor(R.color.home_bottom_text_color_ischeck));
            textView.setTextSize(14);
            addview.addView(relativeLayout);
//            relativeLayout.addView(textView);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.jiance_comeback:
                onBackPressed();
                break;
            case R.id.home_title_share:

                break;
        }
    }


    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    }
}
